<?php
/*
 *网站前台主题文件 
 *
 */
class main extends  site_common
{
	private $productIdArray=array();
	private function commonList(){
		$list=array(1=>$this->getList(1,60),2=>$this->getList(2,15),3=>$this->getList(3,8));
		foreach($list['1'] as $id=>$v){
			$list['1'][$id]['post_summary']=preg_replace('/(\d+)\//U','\1/thumb/',preg_replace('/\,(.*+)/U','',$v['post_summary']));
			}
		$this->pageIntroduction=$this->siteConfig(null,'26<=id && id<=30');
		$this->casePage=ceil(count($list['1'])/16);
		$this->list=$list;
		$designList=$this->imgPlayer('fid=1' ,$limit=15);
		foreach($designList as $id=>$v){
			$temp=(explode('||',$designList[$id]['upload_discription']));
				$designList[$id]['name']=$temp[0];
				$designList[$id]['position']=$temp[1];
				$designList[$id]['description']=$temp[2];
				unset($designList[$id]['upload_discription']);
			}
		$this->designList=$designList;
		$this->friendlink=spClass(friend_link)->findAll();		
	}
	private function leaftoArray($array){
	foreach($array as $id=>$v){
		$this->productIdArray[]=$v['id'];
		if($v['child']){
			$this->leaftoArray($v['child']);
			}
		}
	}		
	function index(){
		$this->pageFlag=0;
		$this->commonList();
		$indexImgList=$this->imgPlayer('fid=2');
		$this->indexImgListNum=count($indexImgList);
		$this->indexImgList=$indexImgList;
		$this->display('foreground/main.html');
	}
	function article(){
		$id=intval($_REQUEST['id']);
		$this->res=$this->getArticle($id,true,0);
		if($id>=1&&$id<=4){
			$this->pageFlag=$id;
		}else if($id==10){
			$this->pageFlag=10086;	
		}else{
			$this->pageFlag=10088;	
		}
		$this->commonList();
		$this->display('foreground/page.html');		
	}
	function supporting(){
		$id=isset($_REQUEST['id'])?intval($_REQUEST['id']):1;//产品分类ID
		$idArrMap=array(1=>5,2=>6,3=>7,4=>8,5=>9);
		$this->res=$this->getArticle($idArrMap[$id],true,0);
		$this->pageFlag=$id;
		$this->commonList();
		$this->pageFlag=8;
		$this->display('foreground/page3.html');
		}
	function  articlelist(){
		$fid=intval($_REQUEST['fid']);
		$page=isset($_REQUEST['page'])?intval($_REQUEST['page']):1;
		if(!in_array($fid,array('2','3'))){
			$this->error404();
			exit;
		}else{
			$this->fid=$fid;	
		}
		$post=spClass('posts');
		$res[0]=$post->findAll($conditions = array('fid'=>$fid,'post_satus'=>'1','post_highlight'=>1),$sort='sid desc',$fields='id,post_title,post_summary,post_datil',$limit=4);
		$res[1]=$post->spPager($page,$pagesize=16)->findAll($conditions = array('fid'=>$fid,'post_satus'=>'1','post_highlight'=>0),$sort='sid desc',$fields='id,post_title,post_summary'); 
		$this->pager = $post->spPager()->getPager();
		$this->list=$res;
		$this->pageFlag=10;	
		$this->friendlink=spClass(friend_link)->findAll();
		$this->display('foreground/list.html');	
	}
	function datil(){
		$id=intval($_REQUEST['id']);
		$res=$this->getArticle($id,$private=true,array('2','3'));
		$fid=$res['fid'];
		$this->recommendList=$this->getList($fid,$limit=10);
		$this->fid=$fid;
		$this->res=$res;
		$this->pageFlag=11;
		$this->friendlink=spClass(friend_link)->findAll();
		$this->display('foreground/datil.html');	
	}
	function furniture(){
		$id=isset($_REQUEST['id'])?intval($_REQUEST['id']):1;//产品分类ID
		import(APP_PATH.'/controller/lib/category.php');
		$ct=spClass("category");
		$result=$ct->findAll('','sid desc');
		$constructSm=new Tree($result);//construct sub menu
		$this->leaftoArray($constructSm->leaf($id));
		$this->productIdArray[]=$id;
		$temp=null;
		$temp=implode(",",$this->productIdArray);//获取当前及所有子类id
		$temp='('.$temp.')';
		$ps=spClass(product_summary);
		$res=$ps->findAll($conditions ="fid in ".$temp." and product_status=1",$sort='show_order desc',$fields=null);
			foreach($result as $temp =>$v){
				$tempArr[$v['pid']][]=$v;
			}
			$this->cartegory=$tempArr;
			$this->commonList();
			$this->pageFlag=7;
			$this->picList=$res;
			$this->display('foreground/page2.html');		
	
	}
function cases(){
		$id=isset($_REQUEST['id'])?intval($_REQUEST['id']):1;//案例ID
		$res=$this->getArticle($id,$private=true,1);
		$res['post_summary']=explode(',',$res['post_summary']);
	    $this->pageFlag=12;
		$this->commonList();
		$this->res=$res;
		$this->display('foreground/page4.html');	
	
	}
function temp(){//临时测试 功能：生成全部页面静态文件的地址
	$this->display('admin/backup.html');//已登录，显示首页	
	}	
}
